<?php
include("connection.php");
include("header.php");
//echo  $ceraterid=$_SESSION['userid'];

?>

<?php


if($_GET['action']=="booking")
{
	$eventid=$_GET['id'];
	$userid = $_SESSION['userid'];
	if($userid=="")
	{
		header("location:login.php");
		exit;
	} else {
		
		$result=mysql_query("SELECT * FROM booking WHERE userid='".$userid."' AND eventid='".$eventid."' ORDER BY bookingid DESC ")or die(mysql_error());
		$num = mysql_num_rows($result);
		
		if($num)
				{
			echo '<font color="#FF0000" size="3" ><h2> dddddddddddddd</h2>you have already  booked for this workshop</font>';
			$row=mysql_fetch_array($result);
	echo " Your Booking id is: <font color='#006633' size='4' >".$row['bookingid']."</font>";
				} 
		else
			{
	mysql_query("INSERT INTO booking (eventid, userid) VALUES ('$eventid','$userid') ") or die(mysql_error());
	
	$result=mysql_query("SELECT * FROM booking WHERE userid='".$userid."' AND eventid='".$eventid."' ORDER BY bookingid DESC ")or die(mysql_error());
	$row=mysql_fetch_array($result);
	echo "<font color='#006633' size='4' >Booked successfully! Your Booking id is".$row['bookingid']."</font>";
	
			}
	
	
	
		}
	
	}


if($_GET['action']=="view")
{
 $id=$_GET['id'];
 
 $q=mysql_query("SELECT * FROM event WHERE id='".$id."'")or die(			    mysql_error());
 
 $row = mysql_fetch_array($q);
 
  	  $eventname=$row["eventname"];
	  $venue=$row["venue"];
	  $date=$row["date"];
	  $starttime=$row["starttime"];
	  $endtime=$row["endtime"];
	  $maixumnumber=$row["maxnum"];
	  $guest=$row["guest"];
	  $des=$row["des"];
	  $payment=$row["payment"];
	  $type=$row["type"];
 
    $time1=$row['time1'];
    $time2=$row['time2'];
	$time3=$row['time3'];
	$time4=$row['time4'];
	$time5=$row['time5'];
	$time6=$row['time6'];
	$time7=$row['time7'];
	$time8=$row['time8'];
	$time9=$row['time9'];
	$time10=$row['time10'];
	
	  $program1=$row['program1'];
	  $program2=$row['program2'];
	  $program3=$row['program3'];
	  $program4=$row['program4'];
	  $program5=$row['program5'];
	  $program6=$row['program6'];
      $program7=$row['program7'];
	  $program8=$row['program8'];
	  $program9=$row['program9'];
	  $program10=$row['program10'];

	 echo'<table width="500" border="0" cellspacing="0" cellpadding="0">
  
    <tr><td>eventname:-</td><td>'.$eventname.'</td></tr>
   <tr> <td>venue:-</td><td>'.$venue.'</td></tr>
   <tr> <td>date:-</td><td>'.$date.'</td></tr>
    <tr><td>starttime:-</td><td>'.$starttime.'</td></tr>
   <tr> <td>endtime:-</td><td>'.$endtime.'</td></tr>
   <tr> <td>maixumnumber:-</td><td>'.$maixumnumber.'</td></tr>
    <tr><td>guest:-</td><td>'.$guest.'</td></tr>
   <tr> <td>describution:-</td><td>'.$des.'</td></tr>
   <tr> <td>payment:-</td><td>'.$payment.'</td></tr>
    <tr><td>event type:-</td><td>'.$type.'</td></tr>
   <tr><td><div align="center">Aganda</div></td></tr>
  <tr> <td>Time interval</td><td>program</td></tr>
   <tr> <td>'.$time1.':-</td><td>'.$program1.'</td></tr>
   <tr> <td>'.$time2.':-</td><td>'.$program2.'</td></tr>
   <tr> <td>'.$time3.':-</td><td>'.$program3.'</td></tr>
	<tr> <td>'.$time4.':-</td><td>'.$program4.'</td></tr>
	 <tr> <td>'.$time5.':-</td><td>'.$program5.'</td></tr>
	  <tr> <td>'.$time6.':-</td><td>'.$program6.'</td></tr>
	  <tr> <td>'.$time7.':-</td><td>'.$program7.'</td></tr>
	<tr> <td>'.$time8.':-</td><td>'.$program8.'</td></tr>
	 <tr> <td>'.$time9.':-</td><td>'.$program9.'</td></tr>
	  <tr> <td>'.$time10.':-</td><td>'.$program10.'</td></tr>
	  <tr> <td><div align="center"><h4>if you want book click </h4><a href="?action=booking&id='.$row['id'].'"><img src="images/book.jpg" border="0"/><a/></td></tr>
  </tr>';
	
	
	
	
	
	
	echo "</table>";

}

else{

$result1=mysql_query("SELECT * FROM event GROUP BY type ASC");
	while($row1 = mysql_fetch_array($result1))
	{
	$ev_type= $row1["type"];
	echo "<h2>".$ev_type."</h2>";
	$result=mysql_query("SELECT * FROM event WHERE type='".$ev_type."'");
	$total = mysql_num_rows($result);
	$i=0;
	 echo'<table width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>EVENT NAME</td>
    <td>VENUE</td>
    <td>DATE</td>
    
    
  </tr>';


	while($i< $total)
	{
	$row=mysql_fetch_array($result);
	
	  $eventname = $row['eventname'];
	  $venue=$row["venue"];
	  $date=$row["date"];
	  //$type=$row["type"];
	
	
	echo"
	<tr>
	<td>".$eventname."</td>
	<td>".$venue."</td>
	<td>".$date."</td>
	<td><a href='?action=view&id=".$row["id"]."'>moredetails<a/></td>
	</tr>";
	
	$i++;
	}
	echo "</table>";
	}
	
}
include("footer.php");
?>


